#include "arrowrectangle.h"

#include <QVBoxLayout>
#include <QLabel>
#include <QPushButton>

ArrowRectangle::ArrowRectangle(QWidget* parent) : QFrame(parent)
{
    setFixedSize(QSize(65, 205));
    setFocusPolicy(Qt::NoFocus);

    QVBoxLayout* layout = new QVBoxLayout;
    layout->setContentsMargins(2, 8, 2, 2);
    setLayout(layout);

    m_label = new QLabel(this);
    m_label->setText("1%");
    m_slider = new QSlider(Qt::Vertical, this);
    m_slider->setMinimum(0);
    m_slider->setMaximum(100);

    QPushButton* iconButton = new QPushButton(this);
    iconButton->setIcon(QIcon::fromTheme(":/images/volume.svg"));
    iconButton->setFlat(true);

    layout->addWidget(m_label);
    layout->addWidget(m_slider);
    layout->addWidget(iconButton);

    initConnect();
}

void ArrowRectangle::initConnect()
{
    connect(m_slider, &QSlider::valueChanged, this, &ArrowRectangle::onValueChanged);
}

int ArrowRectangle::currentVolume()
{
    return m_slider->value();
}

void ArrowRectangle::onValueChanged(int value)
{
    emit volumeChanged(value);
    m_label->setText(QString("%1%").arg(value));
}
